package com.lzx.dormsys.controller;

import java.util.List;

import com.lzx.dormsys.bean.DeviceBean;
import com.lzx.dormsys.core.AjaxResult;
import com.lzx.dormsys.core.controller.BaseController;
import com.lzx.dormsys.core.page.TableDataInfo;
import com.lzx.dormsys.service.IDmsDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * dmsController
 *
 * @author ruoyi
 * @date 2021-09-09
 */
@RestController
@RequestMapping("/deviceAction")
public class DeviceController extends BaseController
{
    @Autowired
    private IDmsDeviceService dmsDeviceService;

    /**
     * 查询dms列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DeviceBean deviceBean)
    {
        startPage();
        List<DeviceBean> list = dmsDeviceService.selectDmsDeviceList(deviceBean);
        return getDataTable(list);
    }


    /**
     * 获取dms详细信息
     */
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return AjaxResult.success(dmsDeviceService.selectDmsDeviceById(deviceId));
    }

    /**
     * 新增dms
     */
    @PostMapping
    public AjaxResult add(@RequestBody DeviceBean deviceBean)
    {
        return toAjax(dmsDeviceService.insertDmsDevice(deviceBean));
    }

    /**
     * 修改dms
     */
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceBean deviceBean)
    {
        return toAjax(dmsDeviceService.updateDmsDevice(deviceBean));
    }

    /**
     * 删除dms
     */
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(dmsDeviceService.deleteDmsDeviceByIds(deviceIds));
    }
}
